package com.ruoyi.web.timer;

import com.ruoyi.system.domain.Purse;
import com.ruoyi.system.domain.TbMember;
import com.ruoyi.system.service.ITbMemberService;
import com.ruoyi.system.service.PurseService;
import com.ruoyi.web.controller.dto.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CouponTimer {

    @Autowired
    private ITbMemberService iTbMemberService;



    //每周星期天凌晨1点   派送 优惠卷
    @Scheduled(cron = "0 0 1 ? * 1")
//    @Scheduled(cron = "0 * * * * ?")
    public void issueCoupon(){
        List<TbMember> tbMembers = iTbMemberService.selectTbMemberList(new TbMember());
        for (TbMember member : tbMembers) {
            if (member.getMemberId()==1){
                //则表示是svip用户  派送5张零门槛10元优惠券
                member.setCouponNum(member.getCouponNum()+5);
                iTbMemberService.updateTbMember(member);
            }

            if (member.getMemberId()==2){
                //则表示是vip用户  派送3张零门槛10元优惠券
                member.setCouponNum(member.getCouponNum()+3);
                iTbMemberService.updateTbMember(member);
            }

            if (member.getMemberId()==3){
                //则表示是vip用户  派送3张零门槛10元优惠券
                member.setCouponNum(member.getCouponNum()+1);
                iTbMemberService.updateTbMember(member);
            }

        }

    }

    @Autowired
    PurseService purseService;

    //佣金发放为每周一8:00,-12:00统一对司机端进行佣金发放
    @Scheduled(cron = "0 0 8,12 ? * 2")
//    @Scheduled(cron = "0 0/1 * * * ?")
//    @Scheduled(cron = "0 * * * * ?")
    public void commission(){
        List<Purse> list= purseService.selectByList();
        for (Purse purse : list) {
            purse.setCash(purse.getCash()+purse.getBrokerage());
            purse.setBrokerage(0.0);
            purseService.updatePurse(purse);


        }
    }



}
